package com.goodmean.common.interceptor;

import com.goodmean.common.User;
import com.jfinal.aop.Interceptor;
import com.jfinal.aop.Invocation;

public class ProjectInterceptor implements Interceptor {
    @Override
    public void intercept(Invocation invocation) {
        User user = invocation.getController().getSessionAttr("user");
        if (user == null){
            invocation.getController().redirect("/");
            return;
        }
        String url = invocation.getController().getControllerKey().trim();
        System.out.println("成功"+url);
        switch (user.getStatus()){
            case  0 : if (!"/admin".equals(url)){
                invocation.getController().redirect("/admin");
                return;
            }
            break;
            case  1 : if (!"/teacher".equals(url)){invocation.getController().redirect("/teacher"); return;}break;
            case  2 : if (!"/instructor".equals(url)){invocation.getController().redirect("/instructor"); return;}break;
            case  3 : if (!"/student".equals(url)){invocation.getController().redirect("/student"); return;}break;
            default : invocation.getController().redirect("/error"); break;
        }
        invocation.invoke();
    }
}
